package com.bls.executor;


import com.bls.executor.environment.MyMQ;

public class MessageProducer {


    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                try {
                    produce(Thread.currentThread().getId());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, String.valueOf(i + 1)).start();
        }
    }

    private static void produce(long threadId) throws Exception {
        MyMQ mq = new MyMQ();
        String EXCHANGE_NAME = "item_topic_exchange";//交换机名称，写死
        String queueName = "test";//要监听的队列名称，可以用时间戳+随机数
        mq.channel.queueDeclare(queueName, false, false, false, null);
        String binding = "7600021286.设备故障";
        mq.channel.queueBind(queueName, EXCHANGE_NAME, binding);//定义要监听的路由类型
        String message = "监听型测试消息-发送者为-"+threadId;
//        String binding = "314539853.设备故障";
        System.out.println("发送消息--"+message);
        mq.channel.basicPublish(EXCHANGE_NAME, binding, null, message.getBytes("UTF-8"));
    }
}
